﻿@model TDT.Land.Entity.Sys_Event
@{
    ViewBag.Title = "insertEvnet";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
<script src="../../Scripts/editor/ckeditor.js" type="text/javascript"></script>
@section HeaderContent{
    <script type="text/javascript">
        function openNew() {
            var dt = new Date();
            var href = "/Event/insertEvent?id=&dt=" + dt.getTime();
            window.location.assign(href);            
        }


        function DoSave() {
            $.ajax({ type: 'POST', url: '/Event/doSaveEvent', data: $('#FEvent').serialize(), success: function (response) {

                switch (response) {
                    case "01": // save fail                                          
                        alert("save true");
                        window.location.assign("/Event/Index");
                        break;

                    case "00": // ko the tao user, save sm_user_store loi                                           
                        alert("save fail");
                        break;

                    default:
                        break;
                }
            }
            });
        }


        function cancel() {
            window.location.assign("/Event/Index");
        }

        $(document).ready(function () {
            CKEDITOR.replace('EventBody');
        });


        $(function () {
            $("#FEvent").ajaxForm({
                iframe: true,
                dataType: "json",
                beforeSubmit: function () {
                    // su kien truoc khi up image
                },
                success: function (result) {
                    cusAlert("Save ok");
                    window.location.assign("/Event/Index");
                },
                error: function (xhr, textStatus, errorThrown) {
                    cusAlert(" fail");
                }
            });
        });

        function SetAltValue(value) {
            var _value = change_alias(value);
            $("#alt").val(_value);
        }

        function change_alias(alias) {
            var str = alias;
            str = str.toLowerCase();
            str = str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ |ặ|ẳ|ẵ/g, "a");
            str = str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g, "e");
            str = str.replace(/ì|í|ị|ỉ|ĩ/g, "i");
            str = str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ |ợ|ở|ỡ/g, "o");
            str = str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, "u");
            str = str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g, "y");
            str = str.replace(/đ/g, "d");
            str = str.replace(/!|@@|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\;|\'| |\"|\&|\#|\[|\]|~|$|_/g, "-");
            /* tìm và thay thế các kí tự đặc biệt trong chuỗi sang kí tự - */
            str = str.replace(/-+-/g, "-"); //thay thế 2- thành 1-
            str = str.replace(/^\-+|\-+$/g, "");
            //cắt bỏ ký tự - ở đầu và cuối chuỗi
            return str;
        }

    </script>

}
@section Toolbar {
    <a class="btn_boder btn_save" onclick="DoSave()">Save</a> 
    <a class="btn_boder btn_cancel" onclick="cancel()"> Cancel</a>
}


<div class="div_insert">

  <form action="/Event/doSaveEvent" method="post" enctype="multipart/form-data" id="FEvent">
               
      <table cellpadding="0" cellspacing="0" class="tb_building">
        <tr>
            <th>
                Tên sự kiện:
            </th>
            <td>@Html.TextBoxFor(p => p.Title, new { onkeyup = "SetAltValue(this.value);" })
            </td>
        </tr>
        <tr>
            <th>Alt</th>
            <td>
                @Html.TextBoxFor(p => p.alt)
            </td>
        </tr>
        <tr>
            <th>Tin chi tiết</th>
            <td>
            @Html.DropDownList("LinkOpen", ViewBag.lstBaiViet != null ? (List<SelectListItem>)ViewBag.lstBaiViet : new List<SelectListItem>(), new { style = "width:100px" })                       
            </td>
        </tr>
        <tr>
            <th>
                Hiển thi Home
            </th> 
            <td>
                @{
                    bool isShowHome = Model.IsShow.ToString() == "True" ? true : false ;                    
                 }

                  @Html.CheckBox("IsShow", isShowHome, Model.IsShow)
                 
            </td>
        </tr>  
        
        <tr>
            <th>
                Chi tiet
            </th>
        </tr>
        <tr>
            <td colspan="2">               
                @Html.TextAreaFor(a => a.EventBody)
            </td>
        </tr>
    </table>
    @Html.Hidden("id", Model.id)
    @Html.Hidden("createDate", Model.createDate)
    </form>


</div>




